#include <condition_variable>
#include <functional>
#include <future>
#include <memory>
#include <mutex>
#include <queue>
#include <thread>
#include <vector>

namespace zh
{
    class ThreadPool final
    {
    public:
        ThreadPool(const ThreadPool& pool)            = delete;
        ThreadPool& operator=(const ThreadPool& pool) = delete;

        ThreadPool(size_t threadCount = std::thread::hardware_concurrency());
        ~ThreadPool();

        using Task            = std::function<void()>;
        using ThreadSharedPtr = std::shared_ptr<std::thread>;

        void doTask();
        void submitTask(const Task& task);

        void start();
        void stop();

        size_t getThreadCount() const;

    private:
        std::vector<ThreadSharedPtr> m_threads;
        std::queue<Task>             m_tasks;
        std::mutex                   m_mutex;
        std::condition_variable      m_condition;
        std::atomic_bool             m_runing;
    };
} // namespace zh